<?php 
namespace Home\Controller;
use Think\Controller;
	
	class IndexController extends CommonController{
		public function index()
		{
			$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'0' order by t1.create_time desc limit 4";
			$tips = M()->query($sql);
			// var_dump($tips);
			$this->assign('tips',$tips);

			//首页分页
			 $count =  M('question')->where("tip='0'")->count();
			$Page = new \Think\Page($count,10);
			$show = $Page->show();
			
			$this->assign('page',$show);
			$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip='0' order by t1.create_time desc limit ".$Page->firstRow.",".$Page->listRows;
			
			$questions = M()->query($sql);

			$this->assign('questions',$questions);
			// echo $show;
			//获取热门的条数
			$this->getHotuser();
			$this->getHotView();
			$this->getHotanswer();

			$this->display();
		}


		 	//全部的帖子
  	
	  	public function all()
	  	{	
	  		$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'0' ";
			$tips = M()->query($sql);
			// var_dump($tips);
			$this->assign('tips',$tips);

			//首页分页
			 $count =  M('question')->where("tip<>'1'")->count();
			$Page = new \Think\Page($count,3);
			$show = $Page->show();
			
			$this->assign('page',$show);
			$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'1' order by t1.create_time desc limit ".$Page->firstRow.",".$Page->listRows;
			
			$questions = M()->query($sql);

			$this->assign('questions',$questions);


	  		layout('top');
	  		$this->display();
	  	}



	  	//未结帖子的控制器
	  	public function unfinish()
	  	{
	  		$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'0' and t1.status='未结贴' order by t1.create_time desc";
			$tips = M()->query($sql);
			// var_dump($tips);
			$this->assign('tips',$tips);

			//首页分页
			 $count =  M('question')->where("tip<>'1' and status='未结贴'")->count();
			$Page = new \Think\Page($count,3);
			$show = $Page->show();
			
			$this->assign('page',$show);
			$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'1' and t1.status='未结贴' order by t1.create_time desc limit ".$Page->firstRow.",".$Page->listRows;
			
			$questions = M()->query($sql);

			$this->assign('questions',$questions);


	  		layout('top');
	  		$this->display();
	  	}

	  		//已经采纳结帖子的控制器
	  	public function finish()
	  	{
	  		$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'0' and t1.status='已采纳' order by t1.create_time desc";
			$tips = M()->query($sql);
			// var_dump($tips);
			$this->assign('tips',$tips);

			//首页分页
			 $count =  M('question')->where("tip<>'1' and status='已采纳'")->count();
			$Page = new \Think\Page($count,3);
			$show = $Page->show();
			
			$this->assign('page',$show);
			$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'1' and t1.status='已采纳' order by t1.create_time desc limit ".$Page->firstRow.",".$Page->listRows;
			
			$questions = M()->query($sql);

			$this->assign('questions',$questions);


	  		layout('top');
	  		$this->display();
	  	}


	  	public function jin()
	  	{
	  			//首页分页
			 $count =  M('question')->where("tip<>'1' and tip<>'0'")->count();
			$Page = new \Think\Page($count,3);
			$show = $Page->show();
			
			$this->assign('page',$show);
			$sql = "select t1.*,t2.face,t2.nickname,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tip<>'1' and t1.tip<>'0' order by t1.create_time desc limit ".$Page->firstRow.",".$Page->listRows;
			
			$questions = M()->query($sql);

			$this->assign('questions',$questions);


	  		layout('top');
	  		$this->display();
	  	}





	}













 ?>